package com.example.springbootsecuritydemo.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chaird
 * @create 2021-06-24 10:31
 */
@RestController
public class HelloController {

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(Authentication authentication) {
        System.out.println(authentication.getName());
        return "hello security";
    }

    @RequestMapping("/hello2")
    @ResponseBody
    public String hello2(Authentication authentication) {
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        return "hello security2";
    }
}
